home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / Shapes.h < prev   
Encoding:
Text File  |  1995-12-11  |  12.9 KB  |  424 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Palette.h
  3.  
  4.     Contains:    Palette Classes Definition
  5.  
  6.     Written by:    Dave Stafford
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- DrawEditor Includes --
  12.  
  13. #ifndef _SHAPES_
  14. #define _SHAPES_
  15.  
  16. #ifndef _COMPILERDEFS_
  17. #include "CompDefs.h"
  18. #endif
  19.  
  20. #ifndef _DRAWEDITORGLOBALS_
  21. #include "DrawEditorGlobals.h"
  22. #endif
  23.  
  24. #ifndef _DRAWEDITORDEF_
  25. #include "DrawEditorDef.h"
  26. #endif
  27.  
  28. #ifndef _PALETTE_
  29. #include "Palette.h"
  30. #endif
  31.  
  32. // -- OpenDoc Includes --
  33.  
  34. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  35. #include <StdTypes.xh>
  36. #endif
  37.  
  38. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  39. #include <StdDefs.xh>
  40. #endif
  41.  
  42.  
  43. //=============================================================================
  44. // Forward Declarations
  45. //=============================================================================
  46. class CPublishLink;
  47. class CSubscribeLink;
  48. class CEmbeddedFrameProxy;
  49. class COrderedList;
  50. class CCloneInfo;
  51.  
  52. //=============================================================================
  53. // Constants
  54. //=============================================================================
  55.  
  56. // ----- handles -----
  57. const short kInTopLeftCorner = 1;
  58. const short kInBottomRightCorner = kInTopLeftCorner + 1;
  59. const short kInTopRightCorner = kInBottomRightCorner + 1;
  60. const short kInBottomLeftCorner = kInTopRightCorner + 1;
  61.  
  62. const short kNumberOfHandles = 4;
  63.  
  64. //=============================================================================
  65. // Enumerations
  66. //=============================================================================
  67.  
  68. // Make shape IDs map to tool IDs
  69. // kEmbeddingShape can equate to the text tool since it is the only tool which
  70. // causes a part to be embedded directly.
  71. enum {
  72.     kRectShape = kRectangleTool,
  73.     kLineShape = kLineShapeTool,
  74.     kOvalShape = kOvalTool,
  75.     kPolygonShape = kPolygonTool,
  76.     kEmbeddingShape = kTextTool            
  77. };
  78.  
  79. //=============================================================================
  80. // CShape
  81. //=============================================================================
  82. class CShape
  83. {
  84. public:
  85.     
  86.     // -- Init --
  87.     CShape(ODSShort numberOfHandles, ODSShort shapeType);
  88.     
  89. public:
  90.     virtual ~CShape();
  91.  
  92. public:
  93.  
  94.     // -- Accessors --
  95.     virtual ODBoolean    IsFrozen() const;
  96.     virtual ODSShort    GetShapeType() const;
  97.     
  98.     // We must remember if we were promised to the clipboard
  99.     // because users cannot modify shapes that are promised.
  100.     ODBoolean            IsPromisedToClipboard() const;
  101.     void                SetPromisedToClipboard(ODBoolean promised);
  102.     
  103.     ODBoolean            GetCanDrawColor();
  104.     void                SetCanDrawColor(ODBoolean toggle);
  105.     void                SetColor(const CRGBColor& color);
  106.     CRGBColor*            GetColor();
  107.     
  108.     virtual ODRgnHandle    GetBoundingRegion() const;    
  109.     virtual void        GetBoundingBox(Rect* bounds) const;    
  110.     virtual void        GetBoundingBox(ODRect* bounds) const;
  111.     
  112.     virtual void        SetBoundingBox(Environment* ev, const Point& anchorPoint,  const Point& currentPoint);
  113.     virtual void        SetBoundingBox(Environment* ev, const Rect& bounds);
  114.     virtual void        SetBoundingBox(Environment* ev, ODShape* bounds);
  115.     
  116.     virtual void        GetUpdateShape(Environment* ev, ODShape* updateShape) const;
  117.     virtual void        GetUpdateBox(Environment* ev, ODRect* updateBox) const;
  118.         
  119.     // ----- Embedding Protocols
  120.     virtual ODBoolean    ContainsProxyForFrame(Environment* ev, ODFrame* frame);    
  121.     virtual void        SetInLimbo(Environment* ev, ODBoolean isInLimbo);    
  122.         
  123.     // ----- Dragging
  124.     virtual void        OffsetShape(Environment *ev, ODCoordinate xDelta, ODCoordinate yDelta);
  125.     virtual ODShape*    CreateDragShape(Environment *ev, ODFacet* facet) = 0;
  126.     virtual void        GetDragRect(Rect* dragRect) const;
  127.     
  128.     // ----- Drawing -----
  129.     void                InvalidateHandles(Environment *ev, ODFrame* frame);
  130.     virtual void         DrawShape(Environment* ev, ODFacet* facet);
  131.     void                DrawHandles();
  132.     virtual void         OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw) = 0;
  133.  
  134.     virtual void        Show(Environment* ev, ODBoolean shown);
  135.             ODBoolean    IsShown();
  136.     
  137.  
  138.     // ----- Selection / Activation -----
  139.     virtual ODBoolean    HitTest(Environment *ev, const Point& where) const = 0;
  140.     ODBoolean            ShapeInRectangle(const Rect& rect) const; // InSelectionRect
  141.     
  142.     virtual void        SelectShape(Environment* ev, ODBoolean state);
  143.     virtual void        Activate(Environment* ev, ODBoolean activating, ODFrame* frame);
  144.     ODBoolean            IsSelected() const
  145.                             {return fSelected;}
  146.     
  147.     // ----- Handles -----
  148.     ODSShort            WhichHandle(const Point& mouse) const;
  149.     void                 CalcHandle(short whichHandle, Rect* bounds) const;
  150.     virtual void        GetHandleCenter(short whichHandle, Point* center) const;
  151.  
  152.     // ----- Resize -----
  153.     virtual void        Resize(Environment *ev, Rect& baseRect, Rect& resizeRect);
  154.     virtual void        ResizeFeedback(ODFacet* facet, short whichHandle, Point& mouseLoc, ODBoolean draw);
  155.                                             
  156.     virtual void        GetResizeRect(ODSShort whichHandle, 
  157.                                             Point& lastLocation, 
  158.                                             Rect* srcRect, 
  159.                                             Rect* dstRect);
  160.  
  161.     virtual ODBoolean    SetFrozen(ODBoolean state);
  162.     
  163.     // ----- OpenDoc Notifications -----
  164.     virtual void         Open(Environment *ev, ODFrame* container);
  165.     
  166.     virtual void         DisplayFrameConnected(Environment *ev, ODFrame* frame);
  167.     virtual void         DisplayFrameAdded(Environment *ev, ODFrame* frame);
  168.     virtual void         DisplayFrameRemoved(Environment *ev, ODFrame* frame);
  169.     virtual void         DisplayFrameClosed(Environment *ev, ODFrame* frame);
  170.     
  171.     virtual void         Dragging(Environment *ev, ODBoolean dragging);
  172.     virtual void         FacetAdded(Environment *ev, ODFacet* facet);
  173.     virtual void         FacetRemoved(Environment *ev, ODFacet* facet);
  174.     
  175.     // ----- DrawEditor Notifications -----
  176.     virtual void         Added(Environment *ev);
  177.     virtual void         Removed(Environment *ev, ODBoolean commit);
  178.  
  179.     // ----- Z Ordering -----
  180.     void                 MoveBefore(Environment* ev, CShape* before);
  181.     void                 MoveAfter(Environment* ev, CShape* after);
  182.     
  183.     // ----- Linking -----
  184.     virtual void         Publish(Environment* ev, CPublishLink *publishLink);
  185.     virtual void         Subscribe(Environment* ev, CSubscribeLink* link);
  186.     virtual void         Unpublish(Environment* ev, CPublishLink* publishLink);
  187.     virtual void         Unsubscribe(Environment* ev);
  188.  
  189.     COrderedList*        GetPublishLinks() const
  190.                             {return fPublishLinks;}
  191.                             
  192.     ODBoolean            IsPublished();
  193.                             
  194.     void                SetSubscribeLink(CSubscribeLink *subscribeLink)
  195.                             {fSubscribeLink = subscribeLink;}
  196.     CSubscribeLink*        GetSubscribeLink() const
  197.                             {return fSubscribeLink;}
  198.     ODBoolean            IsSubscribed() const
  199.                             {return fSubscribeLink != NULL;}
  200.  
  201.     // ----- Storage -----
  202.     virtual void Read(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo);
  203.     virtual void Read(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo);
  204.     virtual void Write(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo);
  205.     virtual void Write(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo);
  206.     
  207.     void SetExternalizationIndex(ODUShort index);
  208.     ODUShort GetExternalizationIndex();
  209.  
  210.  
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // Data Members
  214. //
  215. protected:
  216.     Rect            fRect;
  217.     COrderedList*    fPublishLinks;
  218.     CSubscribeLink*    fSubscribeLink;
  219.  
  220. private:
  221.  
  222.     CRGBColor         fColor;
  223.     ODBoolean        fCanDrawColor;
  224.  
  225.     ODBoolean        fSelected;
  226.     ODBoolean        fPromisedToClipboard;
  227.     ODBoolean        fShown;
  228.     
  229.     ODSShort        fShapeType;
  230.     ODSShort        fNumberOfHandles;
  231.  
  232.     ODUShort        fExternalizationIndex;
  233.  
  234. };
  235.  
  236.  
  237. //=============================================================================
  238. // class CRectangleShape
  239. //=============================================================================
  240.  
  241. class CRectangleShape : public CShape
  242. {
  243. public:
  244.     CRectangleShape(ODSShort shapeType = kRectShape);
  245.     virtual ~CRectangleShape();
  246.                     
  247.     // ----- Shape -----
  248.     virtual                ODShape*    CreateDragShape(Environment *ev, ODFacet* facet);
  249.     
  250.     virtual void        OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw);
  251.     
  252.     virtual ODBoolean    HitTest(Environment *ev, const Point& where) const;
  253.     virtual void         DrawShape(Environment* ev, ODFacet* facet);
  254.  
  255. };
  256.  
  257.  
  258.  
  259. //=============================================================================
  260. // class COvalShape
  261. //=============================================================================
  262.  
  263. class COvalShape : public CShape
  264. {
  265. public:
  266.     COvalShape();
  267.     virtual ~COvalShape();
  268.                 
  269.     // ----- Shape -----
  270.     virtual ODShape*    CreateDragShape(Environment *ev, ODFacet* facet);
  271.     virtual ODRgnHandle    GetBoundingRegion() const;    
  272.     
  273.     virtual void         OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw);
  274.     
  275.     virtual ODBoolean    HitTest(Environment *ev, const Point& where) const;
  276.     virtual void         DrawShape(Environment* ev, ODFacet* facet);
  277.  
  278. };
  279.  
  280.  
  281. //=============================================================================
  282. // class CPolygonShape
  283. //=============================================================================
  284.  
  285. class CPolygonShape : public CShape
  286. {
  287. public:
  288.     CPolygonShape();
  289.     virtual ~CPolygonShape();
  290.                 
  291.     // ----- Inherited API -----
  292.     
  293.     // Shape
  294.     virtual ODShape*    CreateDragShape(Environment *ev, ODFacet* facet);
  295.     virtual ODRgnHandle    GetBoundingRegion() const;    
  296.     
  297.     virtual void        Resize(Environment *ev, Rect& baseRect, Rect& resizeRect);
  298.     
  299.     virtual void         OutlineShape(ODFacet* facet, const Rect& rect, ODBoolean draw);
  300.     
  301.     virtual ODBoolean    HitTest(Environment *ev, const Point& where) const;
  302.     virtual void         DrawShape(Environment* ev, ODFacet* facet);
  303.  
  304.     virtual void        OffsetShape(Environment *ev, ODCoordinate xDelta, ODCoordinate yDelta);
  305.  
  306.     // Storage 
  307.     virtual void Read(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo);
  308.  
  309.     // ----- New API -----
  310.     
  311.     virtual void        SetPolygon(ODSShort numSides);
  312.  
  313. private:
  314.     PolyHandle    fPolygon;
  315.     ODSShort    fSides;
  316.  
  317. };
  318.  
  319.  
  320.  
  321. //=============================================================================
  322. // class CEmbeddingShape
  323. //=============================================================================
  324.  
  325. class CEmbeddingShape : public CRectangleShape
  326. {
  327. public:
  328.     CEmbeddingShape(DrawEditor* drawEditor);
  329.     virtual ~CEmbeddingShape();
  330.                 
  331.     // ----- Inherited Methods -----
  332.     virtual void         DrawShape(Environment* ev, ODFacet* facet);
  333.     virtual void        SelectShape(Environment* ev, ODBoolean state);
  334.     
  335.     virtual void        OffsetShape(    Environment *ev, 
  336.                                         ODCoordinate xDelta, 
  337.                                         ODCoordinate yDelta);
  338.     
  339.     // ----- Embedding Protocols
  340.     virtual ODBoolean    ContainsProxyForFrame(Environment* ev, ODFrame* frame);    
  341.     ODFacet*             GetEmbeddedFacet(Environment* ev, ODFacet* containingFacet);
  342.     ODFacet*             GetEmbeddedFacet(Environment* ev, ODFrame* containingFrame);
  343.     ODFrame*             GetAnyFrame(Environment* ev);
  344.     
  345.     void                 AddFrameProxy(CEmbeddedFrameProxy* frameProxy);
  346.     
  347.     void                 Embed(    Environment* ev, 
  348.                                 ODPart* part, 
  349.                                 ODFrame* containingFrame, 
  350.                                 ODID embeddedFrame);
  351.     
  352.     virtual void        SetInLimbo(Environment* ev, ODBoolean isInLimbo);    
  353.     virtual ODBoolean    SetFrozen(ODBoolean state);
  354.     
  355.     // ----- Drawing -----
  356.     virtual void        Show(Environment* ev, ODBoolean shown);
  357.     
  358.     
  359.     virtual void        SetBoundingBox(Environment* ev, const Point& anchorPoint,  const Point& currentPoint);
  360.     virtual void        SetBoundingBox(Environment* ev, const Rect& bounds);
  361.     virtual void        SetBoundingBox(Environment* ev, ODShape* bounds);
  362.     
  363.     virtual void        SetShapeRectangle(Environment* ev, ODShape* bounds);
  364.     
  365.     virtual void        SetProxyBounds(Environment* ev, const Rect& bounds);
  366.     
  367.     // ----- Z Ordering -----
  368.     void                 MoveFirst(Environment* ev);
  369.     void                 MoveLast(Environment* ev);
  370.     void                 MoveBefore(Environment* ev, CShape* before);
  371.     void                 MoveAfter(Environment* ev, CShape* behind);
  372.     
  373.     
  374.     // ----- Activation -----
  375.     virtual void        Activate(Environment* ev, ODBoolean activating, ODFrame* frame);
  376.     
  377.     // ----- Resize -----
  378.     virtual void        Resize(Environment* ev, Rect& baseRect, Rect& resizeRect);
  379.     
  380.     // ----- OpenDoc Notifications -----
  381.     virtual void         Open(Environment *ev, ODFrame* container);
  382.     
  383.     virtual void         DisplayFrameConnected(Environment *ev, ODFrame* frame);
  384.     virtual void         DisplayFrameAdded(Environment *ev, ODFrame* frame);
  385.     virtual void         DisplayFrameRemoved(Environment *ev, ODFrame* frame);
  386.     virtual void         DisplayFrameClosed(Environment *ev, ODFrame* frame);
  387.     
  388.     
  389.     virtual void         Dragging(Environment *ev, ODBoolean dragging);
  390.     virtual void         FacetAdded(Environment *ev, ODFacet* facet);
  391.     virtual void         FacetRemoved(Environment *ev, ODFacet* facet);
  392.     
  393.     // ----- DrawEditor Notifications -----
  394.     virtual void         Added(Environment *ev);
  395.     virtual void         Removed(Environment *ev, ODBoolean commit);
  396.     
  397.     // ----- Storage -----
  398.     virtual void         Read(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo);
  399.     virtual void         Read(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo);
  400.     virtual void         Write(Environment* ev, ODStorageUnit* storage, CCloneInfo* cloneInfo);
  401.     virtual void         Write(Environment* ev, ODStorageUnitView* view, CCloneInfo* cloneInfo);
  402.     
  403.     // ----- Linking ------
  404.     virtual void         Publish(Environment* ev, CPublishLink* link);
  405.     virtual void         Subscribe(Environment* ev, CSubscribeLink* link);
  406.     
  407.     void ChangeLinkStatus(Environment* ev, ODLinkStatus linkStatus);
  408.     virtual void          Unpublish(Environment* ev, CPublishLink* link);
  409.     virtual void         Unsubscribe(Environment* ev);
  410.     
  411. private:
  412.     DrawEditor*            fDrawEditor;
  413.     
  414.     ODBoolean            fFrozen;
  415.     
  416.     COrderedList*        fFrameProxies;
  417.     ODRect                fFrameRect;
  418.     
  419. };
  420.  
  421.  
  422.  
  423.  
  424. #endif